home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1999 #2
/
Amiga Plus CD - 1999 - No. 2.iso
/
System-Boost
/
Emulatoren
/
warpsnes
/
theguis.lha
/
SNESLauncher.LZX
/
WarpSNES-Launcher.c
< prev
next >
Wrap
C/C++ Source or Header
|
1984-05-03
|
13KB
|
388 lines
#include "demo.h"
#define ID_ABOUT 1
#define ID_NEWFILE 2
#define ID_DOUBLENEWFILE 3
#define ID_NEWVOLUME 4
#define ID_MUTTER 5
#define ID_DVIFILE 6
#define ID_VIEW 7
#define ID_QUIT 8
struct NewMenu Menu[] =
{
{ NM_TITLE, "Project" , 0 ,0,0,(APTR)0 },
{ NM_ITEM , "About..." ,"?",0,0,(APTR)ID_ABOUT },
{ NM_ITEM , NM_BARLABEL, 0 ,0,0,(APTR)0 },
{ NM_ITEM , "Quit" ,"Q",0,0,(APTR)MUIV_Application_ReturnID_Quit },
{ NM_END , NULL , 0 ,0,0,(APTR)0 },
};
int CurPrtNum = 0;
APTR Applic = NULL;
APTR WI_Main;
APTR LV_Files, LV_Volumes, BT_Parent, ST_File, IM_File, BT_View, BT_End;
static char DVIFileBuffer[512];
static char DVIpattern[16];
#define POP_FILE 1
#define POP_OUTP 2
#define POP_LOGF 3
#define PopupArg(ptr,obj,retimg,img,hook,arg)\
HGroup, GroupSpacing(1),\
Child, ptr=obj,\
Child, retimg = ImageObject,\
ImageButtonFrame,\
MUIA_Image_Spec , img,\
MUIA_Image_FontMatchWidth, TRUE,\
MUIA_Image_FreeVert , TRUE,\
MUIA_InputMode , MUIV_InputMode_RelVerify,\
MUIA_Background , MUII_BACKGROUND,\
End,\
TAG_IGNORE, retimg && ptr ? DoMethod(retimg,MUIM_Notify,MUIA_Pressed,FALSE,ptr,3,MUIM_CallHook,hook,arg) : 0,\
End
SAVEDS ASM ULONG FilePopupFunc(REG(a0) struct Hook * hook, REG(a1) void * args, REG(a2) APTR obj)
{
struct Window * window;
long l, t, w, h;
struct FileRequester * req;
char * buf, * cptr, * dir, * file;
int IsDir, GadType;
BPTR lock;
__aligned struct FileInfoBlock fib;
char device[50];
char * title = "";
/* put our application to sleep while displaying the requester */
set(Applic,MUIA_Application_Sleep,TRUE);
GadType = *((long *)args); /* POP_#? */
switch (GadType) {
case POP_FILE:
title = "Select Mp3Song";
break;
case POP_OUTP:
title = "Select Output-File";
break;
case POP_LOGF:
title = "Select Logfile";
break;
}
get(obj,MUIA_String_Contents,&buf);
strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
IsDir = FALSE;
lock = Lock(DVIFileBuffer, ACCESS_READ);
if (lock) {
if (Examine(lock, &fib)) {
if (fib.fib_DirEntryType > 0) IsDir = TRUE;
}
UnLock(lock);
}
if (IsDir) {
file = NULL;
dir = DVIFileBuffer;
}
else {
cptr = strrchr(DVIFileBuffer, '/');
if (cptr) {
dir = DVIFileBuffer;
*cptr = '\0';
file = cptr+1;
}
else {
cptr = strchr(DVIFileBuffer, ':');
if (cptr) {
strncpy(device, DVIFileBuffer, cptr-DVIFileBuffer+1);
device[cptr-DVIFileBuffer+1] = '\0';
dir = device;
file = cptr+1;
}
else {
dir = NULL;
file = DVIFileBuffer;
}
}
}
/* get the calling objects window and position */
get(obj,MUIA_Window ,&window);
get(obj,MUIA_LeftEdge,&l);
get(obj,MUIA_TopEdge ,&t);
get(obj,MUIA_Width ,&w);
get(obj,MUIA_Height ,&h);
if (req=MUI_AllocAslRequestTags(ASL_FileRequest,TAG_DONE)) {
if (MUI_AslRequestTags(req,
ASLFO_Window ,window,
ASLFO_PrivateIDCMP ,TRUE,
ASLFO_TitleText ,title,
ASLFO_InitialLeftEdge,window->LeftEdge + l,
ASLFO_InitialTopEdge ,window->TopEdge + t+h,
ASLFO_InitialWidth ,w,
ASLFO_InitialHeight ,250,
((GadType==POP_FILE) ? ASLFR_InitialPattern : TAG_IGNORE), "#?.smc",
((file) ? ASLFR_InitialFile : TAG_IGNORE), file,
((dir) ? ASLFR_InitialDrawer : TAG_IGNORE), dir,
TAG_DONE)) {
/* set the new contents for our string gadget */
strncpy(DVIFileBuffer, req->fr_Drawer, sizeof(DVIFileBuffer)-1);
AddPart(DVIFileBuffer, req->fr_File, sizeof(DVIFileBuffer)-1);
set(obj,MUIA_String_Contents,DVIFileBuffer);
if (GadType == POP_FILE) {
set(LV_Files, MUIA_Dirlist_Directory, req->fr_Drawer);
}
}
MUI_FreeAslRequest(req);
}
/* wake up our application again */
set(Applic,MUIA_Application_Sleep,FALSE);
return(0);
}
static struct Hook FilePopupHook = {
{NULL, NULL},
(void *)FilePopupFunc,
NULL, NULL
};
/******************************************************/
int main(int argc, char * argv[])
{
init();
/*InitVars(); */
{ /* Homedirectory in String-Gadget */
BPTR lock;
lock = Lock("", ACCESS_READ);
if (lock) {
(void)NameFromLock(lock, DVIFileBuffer, sizeof(DVIFileBuffer)-1);
UnLock(lock);
}
else {
*DVIFileBuffer = '\0';
}
}
(void)ParsePatternNoCase("#?", DVIpattern, 16);
Applic = ApplicationObject,
MUIA_Application_Title , " WarpSNES PPC Launcher V1.0",
MUIA_Application_Version , "$VER: ",
MUIA_Application_Copyright , "Copyright ©1998, Sinan Gurkan",
MUIA_Application_Author , "Sinan Gürkan",
MUIA_Application_Description , "warpsnes",
MUIA_Application_Base , "snes",
MUIA_Application_Menu , Menu,
SubWindow,
WI_Main = WindowObject,
MUIA_Window_Title , "WarpSNES Launcher GUI",
MUIA_Window_ID, MAKE_ID('M','A','I','N'),
WindowContents, VGroup,
Child, TextObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Text_Contents, "\33c\33b\0338WarpSNES PPC Launcher\nWritten 31.7.1998 by Sinan Gurkan\nFeel The PPC Power !", End,
Child, VGroup, GroupFrameT("Select SNES ROM file"),
Child, HGroup,
Child, LV_Files = ListviewObject,
MUIA_Weight, 300,
MUIA_Listview_Input, TRUE,
MUIA_Listview_List, DirlistObject,
InputListFrame,
MUIA_Dirlist_Directory, DVIFileBuffer,
MUIA_Dirlist_AcceptPattern, DVIpattern,
MUIA_Dirlist_RejectIcons, TRUE, End,
End,
Child, VGroup,
Child, LV_Volumes = ListviewObject,
MUIA_Weight, 200,
MUIA_Listview_Input, TRUE,
MUIA_Listview_List, VolumelistObject,
InputListFrame, End,
End,
Child, BT_Parent = SimpleButton("_Parent"),
End,
End,
Child, PopupArg(ST_File, String(DVIFileBuffer,sizeof(DVIFileBuffer)), IM_File, MUII_PopFile, &FilePopupHook, POP_FILE),
Child, BT_View = SimpleButton("_Start EMulation"),
End,
End,
End,
End;
if (!Applic) fail(Applic, "Failed to create application.");
DoMethod(WI_Main,MUIM_Window_SetCycleChain,ST_File,IM_File,LV_Files,BT_Parent,LV_Volumes,BT_View,BT_End,NULL);
DoMethod(LV_Volumes ,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,Applic,2,MUIM_Application_ReturnID,ID_NEWVOLUME);
DoMethod(LV_Files,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,Applic,2,MUIM_Application_ReturnID,ID_NEWFILE);
DoMethod(LV_Files,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,Applic,2,MUIM_Application_ReturnID,ID_DOUBLENEWFILE);
DoMethod(BT_Parent,MUIM_Notify,MUIA_Pressed,FALSE,Applic,2,MUIM_Application_ReturnID,ID_MUTTER);
DoMethod(ST_File,MUIM_Notify,MUIA_String_Acknowledge, MUIV_EveryTime,Applic,2,MUIM_Application_ReturnID,ID_DVIFILE);
DoMethod(BT_View,MUIM_Notify,MUIA_Pressed,FALSE,Applic,2,MUIM_Application_ReturnID,ID_VIEW);
DoMethod(BT_End,MUIM_Notify,MUIA_Pressed,FALSE,Applic,2,MUIM_Application_ReturnID,ID_QUIT);
DoMethod(WI_Main,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,Applic,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
DoMethod(WI_Main, MUIM_Notify,MUIA_Window_InputEvent, "control c", Applic,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
set(WI_Main,MUIA_Window_Open,TRUE);
{
ULONG signal, retsig;
BOOL running = TRUE;
char sinan[256];
char * buf, * cptr;
BPTR lock;
__aligned struct FileInfoBlock * pfib;
int id;
while (running) {
id = DoMethod(Applic,MUIM_Application_Input,&signal);
switch (id) {
case MUIV_Application_ReturnID_Quit:
running = FALSE;
break;
case ID_ABOUT:
MUI_Request(Applic, WI_Main, 0, NULL, "I See..", "WarpSNES Launcher By Sinan Gurkan");
break;
case ID_NEWFILE:
get(LV_Files,MUIA_Dirlist_Path, &buf);
if (buf) {
strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
set(ST_File,MUIA_String_Contents,DVIFileBuffer);
}
break;
case ID_DOUBLENEWFILE:
DoMethod(LV_Files,MUIM_List_GetEntry,-1,&pfib);
get(LV_Files,MUIA_Dirlist_Path, &buf);
strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
set(ST_File,MUIA_String_Contents,DVIFileBuffer);
if (pfib->fib_DirEntryType > 0) {
set(LV_Files,MUIA_Dirlist_Directory,buf);
}
break;
case ID_NEWVOLUME:
DoMethod(LV_Volumes,MUIM_List_GetEntry,-1,&buf);
set(LV_Files,MUIA_Dirlist_Directory,buf);
break;
case ID_MUTTER:
DoMethod(LV_Files,MUIM_List_GetEntry,-1,&pfib);
get(ST_File,MUIA_String_Contents,&buf);
strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
cptr = strrchr(DVIFileBuffer, '/');
if (pfib->fib_DirEntryType < 0 && cptr) {
*cptr = '\0';
cptr = strrchr(DVIFileBuffer, '/');
}
if (!cptr) cptr = strchr(DVIFileBuffer, ':');
if (cptr) {
if (*cptr == ':') cptr++;
*cptr = '\0';
}
set(ST_File,MUIA_String_Contents,DVIFileBuffer);
set(LV_Files,MUIA_Dirlist_Directory,DVIFileBuffer);
break;
case ID_DVIFILE:
get(ST_File,MUIA_String_Contents,&buf);
lock = Lock(buf, ACCESS_READ);
if (!lock) {
set(ST_File,MUIA_String_Contents,DVIFileBuffer);
}
else {
UnLock(lock);
lock = NULL;
strncpy(DVIFileBuffer, buf, sizeof(DVIFileBuffer)-1);
set(LV_Files, MUIA_Dirlist_Directory, DVIFileBuffer);
}
break;
case ID_VIEW:
system("stack 600000");
sprintf(sinan,"warpsnes -nosound -speedhacks -nosecondjoy %s", DVIFileBuffer);
system(sinan);
break;
case ID_QUIT:
break;
}
if (signal)
{
retsig = Wait(signal | SIGBREAKF_CTRL_C);
if (retsig & SIGBREAKF_CTRL_C) running = FALSE;
}
}
}
fail(Applic,NULL);
}